package com.mce.nebula.entity;

import com.mce.nebula.common.BaseEntity;
import com.mce.nebula.enums.UserOrigin;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 用户实体，对应Python的Users模型
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "user_info",
       uniqueConstraints = {
           @UniqueConstraint(columnNames = "email"),
           @UniqueConstraint(columnNames = "phone")
       })
public class User extends BaseEntity {

    
    @Column(name = "email", length = 35, unique = true)
    private String email;
    
    @Column(name = "nick_name", length = 24, nullable = false)
    private String nickName;
    
    @Column(name = "password", length = 128, nullable = false)
    private String password;
    
    @Column(name = "is_active", nullable = false)
    private Boolean isActive = true;
    
    @Column(name = "phone", length = 15, unique = true)
    private String phone;
    
    @Column(name = "real_name", length = 24)
    private String realName;
    
    @Column(name = "client_ip", length = 32)
    private String clientIp;
    
    @Column(name = "rf", length = 32)
    private String rf;
    
    @Column(name = "github_token", length = 256)
    private String githubToken;
    
    @Column(name = "avatar_url", length = 256)
    private String avatarUrl;
    
    @Column(name = "git_user_id")
    private Integer gitUserId;
    
    @Column(name = "is_sys_admin", nullable = false)
    private Boolean sysAdmin = false;
    
    @Column(name = "is_enterprise_admin", nullable = false)
    private Boolean enterpriseAdmin = false;
    
    @Column(name = "logo", length = 2048)
    private String logo;
    
    @Column(name = "enterprise_id", length = 32)
    private String enterpriseId;
    
    @Column(name = "wechat_user_id", length = 32)
    private String wechatUserId;
    
    @Column(name = "user_origin", length = 15)
    private String userOrigin = UserOrigin.REGISTRATION.getCode();
    
    @Column(name = "last_login_time")
    private LocalDateTime lastLoginTime;
    
    @Column(name = "is_exp", nullable = false)
    private Boolean isExp = false;
    
    @Override
    public String toString() {
        return this.nickName;
    }
}